home *** CD-ROM | disk | FTP | other *** search
- UNIT Windex; {Windex - window tools
- BlueRibbon Software John Roncalio
- 34439 Ascott Avenue 603 Cherry Street, Box 432
- Abbotsford, B.C. Sumas, Washington
- CANADA V2S 4V6 U.S.A. 98295 }
-
- {$DEFINE SAFTEY} {Remove this line to make smaller/faster unit}
-
- INTERFACE
- USES
- CRT,
- DOS;
-
- CONST
- Single : BYTE=1; {Single and Double are the usual constants for drawing the}
- Double : BYTE=2; {box around the window.}
- RAM : BYTE = 0;
- Disk : BYTE = 1;
-
- PROCEDURE OpenWindow(TX,TY,BX,BY,FRG,BKG,Border : BYTE;
- Heading : STRING;
- WhereSaved : BYTE);
- PROCEDURE CloseWindow;
-
- IMPLEMENTATION
-
- TYPE
- WindType=RECORD
- Active : BOOLEAN; {has this window been activated?}
- Location : POINTER; {location in ram where window image was stored}
- X1,Y1,X2,Y2, {border coordinates relative to full screen}
- WAttribute : BYTE; {TextAttr last active in this window}
- WhereCursor : WORD; {Cursor location: Lo=X, Hi=Y relative to window}
- END;
-
- VAR
- WA : ARRAY[0..9] OF WindType; {list of window info}
- Vimage : FILE; {window contents on disk}
- LinePointer, {dynamic pointer to current video line}
- RamPlace, {dynamic pointer to saved line of video memory}
- VideoMem : POINTER; {points to start of video ram}
- Vname : STRING[8]; {Vimage file name}
- EndY, {marks last line to read/write}
- RamSeg, {VideoMem segment}
- RamOfs, { " offset}
- VidOfs, {used to incriment VideoMem pointer}
- Wsize, {size of window contents saved on heap/disk}
- WlineSize, {size of one line of the window}
- Vseg,Voff, {video seg,off}
- Wcount : WORD; {multi duty counter/indexer}
- WindRec : WindType; {info on a window}
-
- PROCEDURE NoWindow; {LOCAL TO IMPLEMENTATION}
- BEGIN
- WITH WindRec DO
- BEGIN
- Active:=False;
- {$IFDEF SAFTEY}
- Location:=Nil;
- X1:=1; Y1:=1; X2:=80; Y2:=25;
- Wattribute:=LightGray;
- WhereCursor:=$101; {home: 1,1}
- {$ENDIF}
- END;
- END;
-
- {LOCAL TO IMPLEMENTATION}
- PROCEDURE Box(X1,Y1,X2,Y2,LineStyle:BYTE);
- VAR
- Tl,Tr, {The border line style is usually Single or Double.}
- Bl,Br,Ver: CHAR; {The ASCII charactor codes 32..254 can be used to }
- Counter, {obtain unusual borders -- only a few of which look}
- Columns, {presentable.}
- Rows : INTEGER;
- Line : STRING[80];
- BEGIN
- Columns:=X2-X1-1; Rows:=Y2-Y1-1;
- CASE LineStyle OF
- 1 :BEGIN
- FILLCHAR(Line,80,#196); Line[0]:=CHR(80);
- Tl:=#218; Tr:=#191; Bl:=#192; Br:=#217; Ver:=#179;
- END;
- 2 :BEGIN
- FILLCHAR(Line,80,#205); Line[0]:=CHR(80);
- Tl:=#201; Tr:=#187; Bl:=#200; Br:=#188; Ver:=#186;
- END;
- 32..254:BEGIN
- FillChar(Line,80,LineStyle); Line[0]:=CHR(80);
- Tl:=CHR(LineStyle); Tr:=CHAR(LineStyle);
- Bl:=CHR(LineStyle); Br:=CHR(LineStyle);
- Ver:=CHR(LineStyle);
- END;
- ELSE Exit; {You don't want a border of ^G, do you?}
- END; {case}
- GoToXY(X1,Y1); WRITE(Tl+COPY(Line,1,Columns)+Tr);
- FOR Counter:=1 TO Rows DO
- BEGIN
- GoToXY(X1,Y1+Counter); WRITE(Ver);
- GoToXY(X2,Y1+Counter); WRITE(Ver);
- END;
- GoToXY(X1,Y2); WRITE(Bl+COPY(Line,1,Columns)+Br);
- END;
-
- PROCEDURE OpenWindow(TX,TY,BX,BY,FRG,BKG,Border : BYTE;
- Heading : STRING;
- WhereSaved : BYTE);
- BEGIN
- {$IFDEF SAFETY}
- {exit if illegal parameters}
- IF (BX<=TX+3) OR (BY<=TY+3) OR (FRG>15) OR (BKG>7) OR (FRG=BKG)
- OR (Length(Heading)>BX-TX-1) THEN HALT(5);
- IF (Border=0) OR (Border>2) OR (WhereSaved>1) THEN HALT(5);
- {$ENDIF}
- {get next available window}
- Wcount:=0;
- WHILE (Wcount<10) AND WA[Wcount].Active DO INC(Wcount);
- {$IFDEF SAFETY}
- {halt if no more slots}
- IF Wcount=10 THEN
- BEGIN
- WindRec:=WA[0]; Window(1,1,WindRec.X2,WindRec.Y2); {restore orig window}
- ClrScr; RunError(201);
- END;
- {$ENDIF}
- {save old window info}
- WA[Wcount-1].WhereCursor:=WhereY * $100 + WhereX;
- WA[Wcount-1].WAttribute:=TextAttr;
- Window(1,1,80,25);
- {write window record}
- WlineSize:=2*(BX-TX+1); Wsize:=WlineSize*(BY-TY+1);
- WindRec.Active:=True;
- IF WhereSaved=Disk THEN
- BEGIN
- WindRec.Location:=Nil;
- Vname:=''; STR(Wcount:1,Vname); Vname:='WINDOW.'+Vname;
- ASSIGN(Vimage,Vname); REWRITE(Vimage,WlineSize);
- END
- ELSE
- BEGIN
- GetMem(WindRec.Location,Wsize); {get memory for image & set pointer}
- RamSeg:=Seg(WindRec.Location^); {stored image segment}
- RamOfs:=Ofs(WindRec.Location^); {stored image offset}
- RamPlace:=Ptr(RamSeg,RamOfs);
- END;
- WindRec.X1:=TX; WindRec.Y1:=TY; WindRec.X2:=BX; WindRec.Y2:=BY;
- WA[Wcount]:=WindRec; {add new window info to list}
- {save image}
- EndY:=BY-TY+1;
- VidOfs:=(TY-1)*160 + (TX-1)*2;
- FOR Wcount:=1 TO EndY DO
- BEGIN
- LinePointer:=Ptr(Vseg,VidOfs);
- IF WhereSaved=Disk THEN BlockWrite(Vimage,LinePointer^,1) ELSE
- BEGIN
- Move(LinePointer^,RamPlace^,WlineSize);
- INC(RamOfs,WlineSize);
- RamPlace:=Ptr(RamSeg,RamOfs);
- END;
- INC(VidOfs,160);
- END;
- TextAttr:=Bkg*16+Frg; {set new video attributes}
- Box(TX,TY,BX,BY,Border); {draw box}
- {write heading}
- GoToXY(TX+((BX-TX-Length(Heading)+1) DIV 2),TY);
- WRITE(Heading);
- Window(TX+1,TY+1,BX-1,BY-1); {Make new window}
- ClrScr; {clear new window}
- IF WhereSaved=Disk THEN CLOSE(Vimage);
- END;
-
- PROCEDURE CloseWindow;
- CONST OnDisk:BOOLEAN=False;
- VAR
- Ycount : INTEGER;
- BEGIN
- {count down to last active window}
- Wcount:=9;
- WHILE NOT WA[Wcount].Active DO DEC(Wcount);
- IF Wcount=0 THEN EXIT; {just joking - no window was open!}
- Window(1,1,80,25);
- WindRec:=WA[Wcount];
- OnDisk:=False; {Added 89/03/05}
- IF WindRec.Location=Nil THEN OnDisk:=True; {image was stored on disk}
- WlineSize:=2*(WindRec.X2-WindRec.X1+1);
- Wsize:=WlineSize*(WindRec.Y2-WindRec.Y1+1); {size of memory to free}
- Vseg:=Seg(VideoMem^);
- VidOfs:=(WindRec.Y1-1)*160 + (WindRec.X1-1)*2;
- LinePointer:=Ptr(Vseg,VidOfs);
- IF OnDisk THEN {restore image from disk}
- BEGIN
- Vname:=''; STR(Wcount:1,Vname); Vname:='WINDOW.'+Vname;
- ASSIGN(Vimage,Vname); RESET(Vimage,WlineSize);
- WHILE NOT EOF(Vimage) DO
- BEGIN
- BlockRead(Vimage,LinePointer^,1); {This reads from disk directly to video}
- INC(VidOfs,160); {memory. On a floppy disk it sucks. For}
- LinePointer:=Ptr(Vseg,VidOfs); {snapier results can add a buffer, read}
- END; {to the buffer, and then move the image}
- CLOSE(Vimage); ERASE(Vimage); {to video ram as shown below.}
- END
- ELSE {image was stored on heap}
- BEGIN
- RamSeg:=Seg(WindRec.Location^);
- RamOfs:=Ofs(WindRec.Location^);
- RamPlace:=Ptr(RamSeg,RamOfs);
- EndY:=WindRec.Y2-WindRec.Y1+1;
- FOR Ycount:=1 TO EndY DO
- BEGIN
- Move(RamPlace^,LinePointer^,WlineSize);
- INC(VidOfs,160); INC(RamOfs,WlineSize);
- LinePointer:=Ptr(Vseg,VidOfs);
- RamPlace:=Ptr(RamSeg,RamOfs);
- END;
- FreeMem(WindRec.Location,Wsize);
- END;
- NoWindow; WA[Wcount]:=WindRec; {mark window as closed}
- {set window to lower level}
- Dec(Wcount); WindRec:=WA[Wcount];
- WITH WindRec DO
- BEGIN
- IF Wcount=0 THEN Window(X1,Y1,X2,Y2) ELSE Window(X1+1,Y1+1,X2-1,Y2-1);
- TextAttr:=Wattribute;
- GoToXY(Lo(WhereCursor),Hi(WhereCursor));
- END;
- END;
-
- BEGIN
- {initialize WindowArray list}
- WITH WindRec DO
- BEGIN
- Active:=True;
- X1:=Lo(WindMin)+1;
- Y1:=Hi(WindMin)+1;
- X2:=Lo(WindMax)+1;
- Y2:=Hi(WindMax)+1;
- END;
- WA[0]:=WindRec;
- NoWindow;
- FOR Wcount:=1 TO 9 DO WA[Wcount]:=WindRec;
- {init globals}
- IF Byte(Ptr($40,$49)^)=7 THEN Vseg:=$B000 ELSE Vseg:=$B800;
- Voff:=0;
- VideoMem:=Ptr(Vseg,Voff);
- END.